package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-21
 * Time: 21:24
 */
// API 描述信息
@Api(tags = "TestController 测试接⼝")
@RestController
@RequestMapping("/test")
public class TestController {

    // API ⽅法描述
    @ApiOperation(value = "测试接⼝1，打印hello")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot...";
    }

    @ApiOperation("测试接口2，显示抛出的异常信息")
    @GetMapping("/Exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }

    @ApiOperation("测试接口3，显示抛出的自定义的异常信息")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }

    @ApiOperation("测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam(value = "姓名") @RequestParam("name") @NonNull String name) {
        return AppResult.success("hello : " + name);
    }
}
